package com.yz.rabbitmq;

import com.rabbitmq.client.*;
import org.springframework.util.StringUtils;

import java.io.IOException;

/**
 * 描述：
 **/
public class RabbitmqCon {
    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("111.229.85.126");
        connectionFactory.setVirtualHost("test");
        connectionFactory.setPort(5671);
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("test",true,false,false,null);
        channel.basicConsume("directQueue",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println(consumerTag+" : "+new String(body)+" : "+envelope.getDeliveryTag());
                channel.basicAck(envelope.getDeliveryTag(), false);
                }
        });
    }
}
